<template>
    <div class="programModify">
        <el-form 
            ref="ruleForm" 
            label-width="100px"
            :model="ruleForm"
            :rules="rules">
            <el-form-item label="小程序名称" prop="appname">
                <el-select v-model="ruleForm.appname" placeholder="请选择小程序名称">
                    <el-option label='请选择' value='' ></el-option>
                    <el-option :label=item.appname :value=item.appname v-for="(item,index) in options" :key="index">{{item.appname}}-{{item.appid}}</el-option>
                </el-select>
            </el-form-item>
            <el-upload
                class="upload-demo"
                action="https://www.yyjpai.com/index/operate/uploadsImg"
                :on-success=handleAvatarSuccess
                name="file"
                list-type="picture">
                <el-button size="small" type="primary">点击上传</el-button>
                <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
            </el-upload>
            <el-form-item label="文字1">
                <el-input v-model="ruleForm.title1" placeholder="请输入文字"></el-input>
                <el-button @click="AddInput" v-if="this.add==2?false:true">增加</el-button>
            </el-form-item>
            <el-form-item :label=item.name v-for="(item,index) in inputAdd" :key="index" v-if=item.add>
                <el-input v-model=item.title placeholder="请输入文字"></el-input>
            </el-form-item>
        </el-form>
       <el-button @click="submitForm('ruleForm')" size="medium" class="addSubimit">提交</el-button>
    </div>
</template>
<script>
import { AddData,getChannel } from '@/assets/js'
export default {
    data(){
        return {
            add:0,//点击增加表单
            inputAdd:[//隐藏的表单
                {name:'文字2',text:"",add:false,title:''},
                {name:'文字3',text:"",add:false,title:''}
            ],
            options:[],//下拉
            ruleForm:{//下拉选中
                appname:'',
                title1:""
            },
            rules:{//验证
                appname:[
                    { required: true, message: '请输入活动名称', trigger: 'blur' }
                ]
            }
        }
    },
    mounted:function(){
        getChannel(this)
    },
    methods:{
        AddInput(){//点击增加表单
            if(this.add<=2){
                this.inputAdd[this.add].add = true;
                this.add = this.add + 1;
            }
        },
        handleAvatarSuccess(res, file) {//上传成功之后
            this.ruleForm.logo = file.response.data.logo
        },
        submitForm:function(e){//点击提交
            var data = {
                appname: this.ruleForm.appname,
                logo:this.ruleForm.logo ? this.ruleForm.logo : '',
                title1:this.ruleForm.title1,
                title2:this.inputAdd[0].title,
                title3:this.inputAdd[1].title
            }
            AddData(this,e,data,'operate/addOperate')
            
        }
    }
}
</script>